import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({//全局变量定义
    state: {
        forcedLogin: false,//是否需要强制登录
        hasLogin: false,
        userName: "",
        userId:'',
        token:'',
        pointId:'',
    },
    mutations: {
        login(state, user) {
            console.log("登陆进来")
            state.userName = user.username || '';
            state.hasLogin = true;
            state.userId = user.userId || '';
            state.token = user.token || '';
            state.pointId = user.pointId || '';
            uni.setStorage({
                key:'userInfos',
                data:user
            })
        },
        logout(state) {
           state.userName = "";
           state.hasLogin = false;
           state.userId = '';
           state.token = '';
           state.pointId = '';
           uni.removeStorage({
               key:'userInfos'
           })
        }
    },
    actions: {
    	// lazy loading openid
    	
    }
})

export default store
